package org.net.cms.controller.admin.notice;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.net.cms.config.Result;
import org.net.cms.controller.admin.notice.vo.NoticeReqVO;
import org.net.cms.service.notice.NoticeService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/notice")
@Tag(name = "管理后台 - 公告")
public class NoticeController {

    @Resource
    private NoticeService noticeService;

    @GetMapping("/id")
    @Operation(summary = "获取单个公告")
    public Result getNoticeById(int id) {
        return Result.success(noticeService.getNotice(id));
    }

    @PostMapping("/add")
    @Operation(summary = "新增公告")
    public Result addNotice(@RequestBody NoticeReqVO notice) {
        noticeService.addNotice(notice);
        return Result.success();
    }

    @PostMapping("/update")
    @Operation(summary = "修改公告")
    public Result updateNotice(@RequestBody NoticeReqVO notice) {
        noticeService.updateNotice(notice);
        return Result.success();
    }

    @DeleteMapping("/del")
    @Operation(summary = "删除公告")
    @Parameter(name = "id", description = "要删除的公告id", required = true)
    public Result deleteNotice(int id) {
        noticeService.deleteNotice(id);
        return Result.success();
    }

    @GetMapping("/list")
    @Operation(summary = "查看公告列表")
    @Parameter(name = "type", description = "列表类型，0未发布，1已发布，2全列表", required = true)
    public Result getNoticeList(int type) {
        return Result.success(noticeService.listNotice(type));
    }

}
